package com.ytsky.hctechnologysys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.ytsky.hctechnologysys.dao.StipendMapper;
import com.ytsky.hctechnologysys.entity.Stipend;
import com.ytsky.hctechnologysys.service.StipendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;


@Service
public class StipendServiceImpl implements StipendService {
    @Autowired
    private StipendMapper stipendMapper;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean append(Stipend stipend) {
        return stipendMapper.insert(stipend) > 0;
    }


    @Override
    public PageInfo<Stipend> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        final List<Stipend> stipend = stipendMapper.selectAll();
        PageInfo<Stipend> pageInfo = new PageInfo<>(stipend);
        return pageInfo;
    }



    @Override
    public PageInfo<Stipend> findByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        List<Stipend> stipend = stipendMapper.selectByKeyword(keyword);
        PageInfo<Stipend>  pageInfo = new PageInfo<>(stipend);
        return pageInfo;
    }

    @Override
    public Stipend findById(int id) {
        return stipendMapper.selectById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean modify(Stipend stipend) {
        return stipendMapper.updateById(stipend) > 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean remove(int id) {
        return stipendMapper.deleteById(id) > 0;
    }
}
